package com.qf.im.utils;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ChannelUtils {

    private static Map<Integer, Channel> channelMap = new ConcurrentHashMap<>();
    private static Map<Channel, Integer> channelsMap = new ConcurrentHashMap<>();

    public static void put(Integer uid, Channel channel) {
        channelMap.put(uid, channel);
        channelsMap.put(channel, uid);
    }

    public static Channel get(Integer uid) {
        return channelMap.get(uid);
    }

    public static void remove(Integer uid){
        Channel channel = channelMap.remove(uid);
        if (channel != null) {
            channelsMap.remove(channel);
        }
    }

    public static void remove(Channel channel){
        Integer uid = channelsMap.remove(channel);
        if (uid != null) {
            channelMap.remove(uid);
        }
    }
}
